-- card: 3187 from stack: in.5 -- bmap block id: 7662 -- flags: 0000 -- background id: 3858 -- name: ApplSize ----- HyperTalk script ----- on hideObjects hide cd btn "Try it!" end hideObjects on showObjects show cd btn "Try it!" end showObjects -- part 1 (button) -- low flags: 00 -- high flags: A002 -- rect: left=82 top=185 right=219 bottom=175 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 8192 -- line height: 16 -- part name: Try it! ----- HyperTalk script ----- on mouseUp global errGlobal put FilePath("APPL", "Choose an application please.") into fileName if fileName = empty then exit mouseUp put ApplSize(fileName, "nodialog:errGlobal") into sizes if errGlobal ≠ empty then answer "Error: “" & errGlobal & "”" put empty into errGlobal else answer "The application “" & fileName & "” is currently set" && "to use" && item 1 of sizes div 1024 & "K, and requires" && "at least" && item 2 of sizes div 1024 & "K." end if end mouseUp -- part contents for background part 20 ----- text ----- XFCN to return the suggested memory size (in bytes) of the application specified by pathName. It returns a comma delimited list with the current size setting in item 1, and the minimum size setting in item 2. Calling Syntax: AppleSize(pathName,«“nodialog”:errorGlobal») PATHNAME : the full path name to the file Note: Occasionally, you will get a value for the minimum size that differs from the Finder's Get Info window. This is because we are reading the true "Minimum" value set by the application and not the "Suggested" value, which is what the Finder uses. -- part contents for background part 38 ----- text ----- 4/50 -- part contents for background part 42 ----- text ----- { ApplSize(Pathname) } { XFCN to return the suggested memory size of the } { application specified by pathName. Looks for current size } { setting or returns minimum size currently set. For some } { reason, the minimum memory value is not always correct. } { } {} {} { Written by: Anup Murarka Eric Carlson } { ALINK: SKEPTIC ALINK: cyNic } { CIS: 76004,3356} {} { We are part of the Support Tools Development Group, } { Apple Computer, Inc. } {} { please DO NOT contack Mac DTS for support of this code! } {} { please DO contact the authors for support of this code! } {} { Send comments, bug reports, requests to any of the above } { E-mail addresses or to: } {} { (one of us) } { Apple Computer, Inc. } { 900 E. Hamilton, Ave. } { Campbell, CA 95008 } { M/S 72-L } {} { Copyright: © 1989, 1990 by Apple Computer, Inc., all rights reserved. } {} { written by : Anup Murarka } { AppleLink : Skeptic } { modification history } { Date Initials Comments } { ---- ------ -------------------------------------------------------- } { 8/14/89 akm first written } { 8/29/90 ec removed upper case converion for A/UX compatibility. add } { StripAddress Changed version to 1.1 } {} unit DummyUnit; interface uses HyperXCmd; procedure MAIN (paramPtr: XCmdPtr); implementation procedure ApplSize (paramPtr: XCmdPtr); FORWARD; procedure MAIN (paramPtr: XCmdPtr); begin ApplSize(paramPtr); end; procedure reportToUser (paramPtr: XCmdPtr; msgStr: str255); {} { report something back to the user. } { the last parameter (optional) to an external may contain } { "noDialog" or "noDialog:GlobalName". GlobalName is the name } { of a HyperTalk global variable into which error messages will be } { placed. we've decided to use this approach to avoid confusing } { an error message with a valid result being returned from an XFCN. } {} var tempStr: str255; begin {check the last param to see if the user requested that} { we suppress the error dialog } ZeroToPas(paramPtr, paramPtr^.params[paramPtr^.paramCount]^, tempStr); UprString(tempStr, true); if pos('NODIALOG', tempStr) = 0 then { no special error handling specified, throw up a dialog and return the error message } begin SendCardMessage(paramPtr, concat('answer "', msgStr, '"')); paramPtr^.returnValue := PasToZero(paramPtr, msgStr); end else if (pos(':', tempStr) > 0) then { requested global AND noDialog so we fill in the global and return empty } begin tempStr := copy(tempStr, pos(':', tempStr) + 1, length(tempStr)); { get the name of the HC global to fill } SetGlobal(paramPtr, tempStr, PasToZero(paramPtr, msgStr)); { and fill it } paramPtr^.returnValue := PasToZero(paramPtr, ''); { return empty } end else { requested noDialog only so we return the error condition as the result } paramPtr^.returnValue := PasToZero(paramPtr, msgStr); end; { procedure } function AskedForHelp (paramPtr: XCmdPtr; syntaxMsg: Str255; copyrightMsg: Str255): boolean; { check to see if the user sent a '?' or a '!' as } { the only parameter. if so we will respond with } { the calling syntax or the copyright/version info } { for this external } {} var firstStr: str255; begin askedForHelp := false; if paramPtr^.paramCount = 1 then begin ZeroToPas(paramPtr, paramPtr^.params[1]^, firstStr); { what is the first param? } if firstStr = '?' then begin reportToUser(paramPtr, syntaxMsg); askedForHelp := true end { asked for help } else if firstStr = '!' then begin reportToUser(paramPtr, copyRightMsg); askedForHelp := true end; { asked for copyright info } end; { one parameter passed } end; { function } function LongToString (paramPtr: XCmdPtr; num: LONGINT): Str255; { why, oh why did dan write this one as a procedure??? } var tempStr: str255; begin LongToStr(paramPtr, num, tempStr); LongToString := tempStr; end; function NumberToString (paramPtr: XCmdPtr; num: LONGINT): Str255; { use the toolbox call rather than HC's } var tempStr: str255; begin NumToString(num, tempStr); NumberToString := tempStr; end; procedure reportResError (paramPtr: XCmdPtr; errorNum: integer); var errMsg, tempName: str255; begin case errorNum of { what caused the problem? } -0: errMsg := 'no error.'; -36: errMsg := 'I/O Error.'; -37: errMsg := 'bad file name or volume name.'; -38: errMsg := 'file not open.'; -39: errMsg := 'that file has no resource fork.'; -42: errMsg := 'too many files open.'; -43: errMsg := 'file not found.'; -45, -54, -61: errMsg := 'file locked.'; -47, -49: errMsg := 'file is busy.'; -53: errMsg := 'that volume is not on line.'; -108: errMsg := 'not enough room in heap zone.'; -120: errMsg := 'directory not found.'; -121: errMsg := 'too many working directories open.'; -127: errMsg := 'internal file system error.'; -192: errMsg := 'resource not found.'; -193: errMsg := 'file not found.'; otherwise errMsg := concat('unexpected error #', NumberToString(paramPtr, errorNum)); end; { case } errMsg := concat('Sorry, ', errMsg); reportToUser(paramPtr, errMsg); { return the error message } end; { function } function getParams (paramPtr: XCmdPtr; var inputFile: str255): boolean; { function to get the parameters and validate them. Returns boolean} { instructing the main procedure to continue if the parameters passed} { are valid. Also returns syntax messages if requested by the user.} var numParams: integer; inputCh: str255; syntaxStr, copyrightStr: str255; begin getParams := true; {Initially, assume the parameters are valid.} syntaxStr := 'ApplSize(pathname «, “nodialog:”errorGlobal»)'; copyrightStr := '© 1989, 1990 Apple Computer, Inc., v.1.1, by Anup Murarka'; {check that we have the proper number of parameters} numParams := paramPtr^.paramCount; if (numParams < 1) or (numParams > 2) then begin getParams := false; reportToUser(paramPtr, syntaxStr); exit(GetParams); end; { asking for help or copyright info? } if AskedForHelp(paramPtr, syntaxStr, copyrightStr) then begin getParams := false; exit(getParams); end; { convert HyperCard's zero terminated string to a Pascal string} ZeroToPas(paramPtr, paramPtr^.Params[1]^, inputFile); end; function curResLoad: boolean; { return the current setting of the system 'ResLoad'. Are resources } { actually loaded or not?} const ResLoad = $A5E; { determines whether or not resources are pre-loaded} type booleanPtr = ^boolean; begin curResLoad := booleanPtr(ResLoad)^; end; procedure ApplSize (paramPtr: XCmdPtr); label 10, 20; type SIZEptr = ^SIZErec; SIZErec = record bkgndFlags: integer; MemorySize: longint; MinMemSize: longint; end; var paramsOK, oldResLoad: boolean; oldCurResFile: integer; WDVRefNum: integer; inputFile: str255; inputRefNum: integer; DirID: longint; wdParams: WDPBRec; error: OSErr; SIZErecHndl: handle; inputSIZE: SIZEptr; CurrentSize, MinimumSize, result: str255; begin paramsOK := getParams(paramPtr, inputFile); if paramsOK = false then exit(ApplSize); oldResLoad := curResLoad; oldCurResFile := curResFile; SetResLoad(FALSE); { avoid slow preloads } inputRefNum := OpenRFPerm(StringPtr(StripAddress(@inputFile))^, 0, fsRdPerm); error := resError; if error <> noErr then begin reportResError(paramPtr, error); goto 10; end; SetResLoad(TRUE); SIZErecHndl := Get1Resource('SIZE', 0); if SIZErecHndl = nil then begin { if 'SIZE' 0 is not available, then try 'SIZE' -1} SIZErecHndl := Get1Resource('SIZE', -1); if SIZErecHndl = nil then begin reportToUser(paramPtr, 'Could not load ‘SIZE’ resources'); goto 20; end; end; MoveHHi(SIZErecHndl); HLock(SIZErecHndl); inputSIZE := SIZEptr(SIZErecHndl^); CurrentSize := LongToString(paramPtr, inputSIZE^.MemorySize); MinimumSize := LongToString(paramPtr, inputSIZE^.MinMemSize); HUnLock(SIZErecHndl); ReleaseResource(SIZErecHndl); result := concat(CurrentSize, chr(44), MinimumSize); paramPtr^.returnValue := PasToZero(paramPtr, result); 20: CloseResFile(inputRefNum); 10: SetResLoad(oldResLoad); UseResFile(oldCurResFile); end; end.